package com.wind.taobao.api.trade.itemprop.convert
{
	import com.wind.taobao.api.trade.itemprop.model.SellerAuthorize;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * SellerAuthorize转换器
	 * @author fxy
	 *
	 */
	public class SellerAuthorizeConvert
	{
		/**
		 * 转换SellerAuthorize集合
		 */
		public static function convertSellerAuthorizes(value:Object, type:String="json"):ArrayCollection
		{
			var sellerAuthorizes:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							sellerAuthorizes.addItem(convertSellerAuthorize((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return sellerAuthorizes;
		}

		/**
		 * 转换SellerAuthorize
		 */
		public static function convertSellerAuthorize(value:Object, type:String="json"):SellerAuthorize
		{
			var sellerAuthorize:SellerAuthorize=new SellerAuthorize();
			if (value == null)
				return sellerAuthorize;
			if (type == TaobaoConstants.XML)
			{
				sellerAuthorize=convertXMLToSellerAuthorize(XML(value), sellerAuthorize);
			}
			else
			{
				sellerAuthorize=convertJSONToSellerAuthorize(value, sellerAuthorize);
			}
			return sellerAuthorize;
		}

		/**
		 * JSON转换为SellerAuthorize
		 */
		private static function convertJSONToSellerAuthorize(json:Object, sellerAuthorize:SellerAuthorize):SellerAuthorize
		{
			if (json.hasOwnProperty(TaobaoConstants.BRANDS))
			{
				sellerAuthorize.brands=BrandConvert.convertBrands(json[TaobaoConstants.BRANDS]);
			}
			if (json.hasOwnProperty(TaobaoConstants.ITEM_CATS))
			{
				sellerAuthorize.item_cats=ItemCatConvert.convertItemCats(json[TaobaoConstants.ITEM_CATS]);
			}
			return sellerAuthorize;
		}

		/**
		 * XML转换为SellerAuthorize
		 */
		private static function convertXMLToSellerAuthorize(value:XML, sellerAuthorize:SellerAuthorize):SellerAuthorize
		{
			return sellerAuthorize;
		}
	}
}